<?php
namespace script;
use script\Observer;
//观察者处理类
class ObserverBase
{
    /**
     * 添加观察者
     */
    private $objs = [];
    public function add(Observer $obj)
    {
        $this->objs[] = $obj;
    }
    /**
     * 执行观察者得操作
     */
    public function notify()
    {
        foreach ($this->objs as $value) {
            $value->update();
        }
    }
    //在对象销毁时执行观察者逻辑
    public function __destruct()
    {
        $this->notify();
    }
    
}